home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-26 | 5.6 KB | 151 lines | [TEXT/ZBAS] |
- 'GraphicUtils.incl by Robert Hommel
- '© Copyright 1994
- 'All rights granted for any use whatsoever
-
- 'Disclaimer: I've tested these routines quite thoroughly on my Mac
- 'LC running System 7.01 and FB 1.02c. I make no promises or warranties
- 'of any kind.
- '*********************************************************************
-
- COMPILE 0, _MacsBugLabels _caseInsensitive _STRResource
- INCLUDE FILE _aplIncl
- DEFSTR LONG
- DEFINT A-Z
-
- '--------------------------- GLOBALS --------------------------------
-
- GLOBALS "GraphicUtils.glbl"
-
- END GLOBALS
-
- '------------------ OFF SCREEN GRAPHICS UTILS -----------------------
-
- CLEAR LOCAL MODE 'returns an offscreen GWorld
- DIM rect;8 'warning: use only with 32-bit color QuickDraw
- LOCAL FN GetOffScrnGWorld&(rect;8)
- CALL LOCALTOGLOBAL(#rect.top%)
- CALL LOCALTOGLOBAL(#rect.bottom%)
- QDErr = FN NEWGWORLD(offPort&,0,rect,0,0,0) 'offPort contains offScreen port
- LONG IF QDErr 'check for error
- LONG IF offPort&
- CALL DISPOSEGWORLD(offPort&) 'dump GWORLD block if necessary
- END IF
- offPort&=0
- END IF
- CALL GLOBALTOLOCAL(#rect.top%)
- CALL GLOBALTOLOCAL(#rect.bottom%)
- END FN = offPort&
-
-
-
-
-
- LOCAL MODE 'this routine sets up a B&W offscreen bitmap
- DIM rect;0,t,l,b,r '(works on any Macintosh)
- LOCAL FN GetOffScrnPort& (rect;8)
- CALL GETPORT(currPort&)
- offPort& = FN NEWPTR(_portRec) 'allocate ptr block (_portRec = GrafPortSize)
- LONG IF offPort& <> 0
- CALL OPENPORT(offPort&)
- RowBytes = (((r-l)+15)/8) AND &7FFE 'get rowbytes (one pixel deep)
- MapSz& = RowBytes * ((b-t)+1) 'calc memory needed
- LONG IF MapSz& < FN FREEMEM + 32000 '32K extra for good measure
- BLOCKMOVE @rect, offPort&+_portRect, 8 'make port rect the correct size
- VisRgn& = [offPort&+_visRgn] 'get visible region
- CALL RECTRGN(VisRgn&,rect) 'make it our rect
- ClipRgn& = [offPort&+_clipRgn] 'do same for clip region
- CALL RECTRGN(ClipRgn&,rect)
- Map& = FN NEWPTR(MapSz&) 'pointer for bitmap and screenbits
- LONG IF Map& <> 0
- offPort&.portBits& = Map& 'set map as portbits (B&W bitmap)
- offPort&.portBits.rowBytes% = RowBytes'needs to know width in bytes
- BLOCKMOVE @rect, offPort&+_portBits+_bounds, 8'needs rect too
- END IF
- XELSE 'Not enough memory here...
- CALL CLOSEPORT(offPort&) 'not enought memory some dump port
- OSErr = FN DISPOSPTR(offPort&) 'and its pointer
- END IF
- END IF
- CALL SETPORT(currPort&) 'point us back to where we were
- END FN = offPort&
-
-
-
-
- LOCAL MODE 'this routine gets a pointer to a port/gWorld
- DIM wndPort&, Gdevice& 'for GETGWORLD
- LOCAL FN GetCurrPort
- LONG IF gColorDepth = 32 'do we have 32-bit QuickDraw?
- CALL GETGWORLD(wndPort&,Gdevice&) 'set port to our new gWorld
- XELSE
- CALL GETPORT(wndPort&) 'get pointer to window’s GrafPort
- END IF
- END FN=wndPort&
-
-
-
-
- LOCAL MODE 'routine sets output to a specific port/gWorld
- LOCAL FN SetThePort (thePort&) '(depends on color or black and white)
- LONG IF gColorDepth = 32 'do we have 32-bit QuickDraw?
- gDev& = FN GETGWORLDDEVICE(thePort&)
- CALL SETGWORLD(thePort&,0) 'set port to offScreen GWorld
- XELSE
- CALL SETPORT(thePort&) 'else do it the old way
- END IF
- END FN
-
-
-
-
- LOCAL MODE 'copy bitmap from offscreen to window
- DIM sRect.8,dRect.8
- LOCAL FN CopyOffScreenBits (offPort&,wndPort&,sRect;8,dRect;8,copyMode,maskRgn&)
- LONG IF gColorDepth = 32 'if 32-bit QuickDraw...
- locked = FN LOCKPIXELS(FN GETGWORLDPIXMAP(offPort&))
- LONG IF locked
- CALL COPYBITS(#offPort&+2,#wndPort&+2,sRect,dRect,copyMode,maskRgn&)
- CALL UNLOCKPIXELS(FN GETGWORLDPIXMAP(offPort&))
- END IF
- XELSE 'do this if not 32-bit QD
- CALL COPYBITS(#offPort&+2,#wndPort&+2,sRect,dRect,copyMode,maskRgn&)
- END IF
- END FN
-
-
-
-
- CLEAR LOCAL
- LOCAL FN DisposeGrafPort(grafPtr&)
- osErr=0
- LONG IF gColorDepth = 32
- CALL DISPOSEGWORLD(grafPtr&) 'dump offscreen GWORLD block
- XELSE
- CALL CLOSEPORT(grafPtr&) 'dump offscreen B&W port
- osErr = FN DISPOSPTR(grafPtr&) 'and its other stuff
- END IF
- END FN=osErr
-
-
-
- '---------------------- GENERAL GRAPHIC UTILS -----------------------
-
-
- CLEAR LOCAL
- LOCAL FN CenterRect(@smallRectPtr&,@bigRectPtr&)
- 'sets smallRect to a rectangle centered inside of bigRect. Does nothing
- 'if smallRect>=bigRect.
-
- smallRectV=smallRectPtr&.bottom%-smallRectPtr&.top%
- smallRectH=smallRectPtr&.right%-smallRectPtr&.left%
- bigRectV=bigRectPtr&.bottom%-bigRectPtr&.top%
- bigRectH=bigRectPtr&.right%-bigRectPtr&.left%
- LONG IF smallRectV<bigRectV AND smallRectH<bigRectH
- %smallRectPtr&+_top,bigRectPtr&.top%+INT(.5*(bigRectV-smallRectV))
- %smallRectPtr&+_left,bigRectPtr&.left%+INT(.5*(bigRectH-smallRectH))
- %smallRectPtr&+_bottom,smallRectPtr&.top%+smallRectV
- %smallRectPtr&+_right,smallRectPtr&.left%+smallRectH
- END IF
- END FN
-
-